//
//  LZTableViewCell.m
//  沙哈拉FM
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 S1mpl3. All rights reserved.
//

#import "LZTableViewCell.h"
#import "FitHeader.h"
#import "UIImageView+WebCache.h"
#import "LZMusicSingleton.h"
#import "TabBarController.h"
#import "Model.h"

@implementation LZTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
        [self changeColor];
    }
    return self;
}

-(void)changeColor{
    self.backgroundColor = [Model shareInstance].ViewColor;
}

- (void)createView{
    _flag = 0;
    _coverSmallImageView = [[UIImageView alloc]init];
    _coverSmallImageView.layer.cornerRadius = 25 * FITWidth;
    _coverSmallImageView.clipsToBounds = YES;
    [self.contentView addSubview:_coverSmallImageView];
    
//    _littleImageView = [[UIImageView alloc]init];
//    _littleImageView.image = [UIImage imageNamed:@"播放.png"];
//    _littleImageView.userInteractionEnabled = YES;
//    _littleImageView.contentMode = UIViewContentModeScaleAspectFit;
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(littleImageViewAction)];
//    [_littleImageView addGestureRecognizer:tap];
//    [self.contentView addSubview:_littleImageView];
    
    _createdAtLabel = [[BaseLabel alloc]init];
    _createdAtLabel.textAlignment = 1;
    [self.contentView addSubview:_createdAtLabel];
    
    _titleLabel = [[BaseLabel alloc]init];
    _titleLabel.numberOfLines = 0;
    _titleLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:_titleLabel];
    
    _nicknameLabel = [[BaseLabel alloc]init];
    _nicknameLabel.font = [UIFont systemFontOfSize:13];
    _nicknameLabel.alpha = .7;
    [self.contentView addSubview:_nicknameLabel];
    
//    _button = [BaseButton buttonWithType:UIButtonTypeCustom];
//    [_button setImage:[UIImage imageNamed:@"下载.png"] forState:UIControlStateNormal];
//    _button.layer.borderWidth = .5;
//    [_button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
//    [self.contentView addSubview:_button];
    
}
//#pragma mark - 图片中的播放点击事件
//- (void)littleImageViewAction{
//    if (_flag == 0) {
//        _littleImageView.image = [UIImage imageNamed:@"暂停.png"];
////        [[LZMusicSingleton shareInstance] play:_playPath64String];
//       // [[TabBarController shareInstance] AudioWillPlay:_playPath64String];
////        NSLog(@"播放");
//        _flag = 1;
//    }else{
//        _littleImageView.image = [UIImage imageNamed:@"播放.png"];
//        [[LZMusicSingleton shareInstance] pause];
////        NSLog(@"暂停");
//        _flag = 0;
//    }
//}
//#pragma mark - 下载点击事件
//- (void)buttonAction{
//    if (_flag == 0) {
//        [_button setImage:[UIImage imageNamed:@"对号.png"] forState:UIControlStateNormal];
////        NSLog(@"下载");
////        _flag = 1;
//    }
////    else{
////        [_button setImage:[UIImage imageNamed:@"下载.png"] forState:UIControlStateNormal];
////        _flag = 0;
////        NSLog(@"取消下载");
////    }
//}
- (void)layoutSubviews{
    [super layoutSubviews];
    _createdAtLabel.frame = CGRectMake(10 * FITWidth, 0, 30 * FITWidth, 80 * FITHeight);
    _coverSmallImageView.frame = CGRectMake(_createdAtLabel.frame.origin.x + _createdAtLabel.frame.size.width + 5 * FITWidth, 10 * FITHeight, 50 * FITWidth, 50 * FITHeight);
//    _littleImageView.frame = CGRectMake(_coverSmallImageView.frame.origin.x + 15 * FITWidth, _coverSmallImageView.frame.origin.y + 15 * FITHeight, 20 * FITWidth, 20 * FITHeight);
    _titleLabel.frame = CGRectMake(_coverSmallImageView.frame.origin.x + _coverSmallImageView.frame.size.width + 10 * FITWidth, _coverSmallImageView.frame.origin.y, 250 * FITWidth, 40 * FITHeight);
    _nicknameLabel.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.origin.y + _titleLabel.frame.size.height + 5 * FITHeight, _titleLabel.frame.size.width, 20 * FITHeight);
//    _button.frame = CGRectMake(_nicknameLabel.frame.origin.x + _nicknameLabel.frame.size.width - 5 * FITWidth, _titleLabel.frame.origin.y + _titleLabel.frame.size.height, 20 * FITWidth, 20 * FITHeight);
}
- (void)setLzModel:(LZBillboardModel *)lzModel{
    
      
    if (_fromZBB) {
      
          [_coverSmallImageView sd_setImageWithURL:[NSURL URLWithString:lzModel.albumCoverUrl290] placeholderImage:[UIImage imageNamed:@"100*100"]];
    }
    else
    {
          [_coverSmallImageView sd_setImageWithURL:[NSURL URLWithString:lzModel.coverSmall] placeholderImage:[UIImage imageNamed:@"100*100"]];
    }
  
    [self changeColor];
    _titleLabel.text = lzModel.title;
    _nicknameLabel.text = [NSString stringWithFormat:@"by %@", lzModel.nickname];
    _playPath64String = lzModel.playPath64;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
